< previous page page_377 next page >

Page 377
Modify the PRJMOVE.VBP project to illustrate the Find method by adding another button to the project. Set the button's Name property to cmdFind and its Caption property to F&ind. Next, add the code in Listing 10.5 to the cmdFind_Click event.
Type.gifListing 10.5. Coding the cmdFind_Click event.
Private Sub cmdFind_Click()
    '
    ' use the find method for non-table searches
    '
    Dim strFind As String
    '
    strFind = InputBox("Enter an Author ID to Find:", "Non-table Find", "13")
    strFind = Trim(strFind)
    '
    If strFind <> "" Then
        strFind = "AUID=" & strFind
        rs.FindFirst strFind
        '
        If rs.NoMatch = True Then
            MsgBox "Unable to locate [" & strFind & "]", vbExclamation, "Non-
arrow.gifTable Find Failed"
        Else
            ReadRow
            MsgBox "Found [" & strFind & "]", vbInformation, "Non-table Find
arrow.gifSucceeded"
        End If
    End If
    '
End Sub
Listing 10.5 is almost identical to the code used in the cmdSeek_Click event (refer to Listing 10.4). Notice that you have to build the criteria string to include the name of the field you are searching. Because the Find method can be applied to any field (or fields) in the table, you must supply the field in the search criteria.
Before saving the project, comment out the line in the Form_Load event that sets the index. Also, change dbOpenTable to dbOpenSnapshot. Now save and run the project. When you click the Find button, enter 13 in the input box. You should see a message telling you that the Find operation was successful (see Figure 10.3).
0377-01.jpg
Figure 10.3.
The results of the non-
table 
Find method.

 
< previous page page_377 next page >

If you like this book, buy it!